package com.team10.hotel.service.impl;

import com.sun.xml.internal.bind.v2.model.core.ID;
import com.team10.hotel.domain.User;
import com.team10.hotel.mapper.UserMapper;
import com.team10.hotel.service.UserService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAllUserAndRoleName() {
        return userMapper.selectAllUserAndRoleName();
    }

    @Override
    public User findUserAndRoleNameByPrimaryKey(String userId) {
        return userMapper.selectUserAndRoleNameByPrimaryKey(userId);
    }

    @Override
    public User findByPrimaryKey(String id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int saveOrUpdate(User user) {
        if (StringUtils.isNotBlank(user.getUserId())){
            return userMapper.updateByPrimaryKeySelective(user);
        }else {
            return userMapper.insert(user);
        }
    }

    @Override
    public int deleteUser(String id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public User findUserByTel(String userTel) {
        return userMapper.findUserTel(userTel);
    }

    @Override
    public User findUserByEmail(String userEmail) {
        return userMapper.findUserEmail(userEmail);
    }

    @Override
    public int saveUser(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User password(String password) {
        return userMapper.password(password);
    }

}
